package protocol.JT808_2019;

import java.util.HashMap;

public class Handle808_2019JT09 implements IHandle808_2019JT {

    @Override
    public String handle(JT808_2019Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle0900(cmd);
            case 0x01:
                return handle0901(cmd);
            default:
                return "808-2019:未匹配的命令字"+(cmd.readOrder()+","+cmd.subOrder());
        }
    }

    private String handle0901(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:数据压缩上报");
        builder.append("\r\n");

        int size = cmd.readDWORD();
        builder.append("压缩消息长度:"+size);
        builder.append("\r\n");

        builder.append("压缩消息体:"+cmd.readBCD(size));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0900(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:数据上行透传");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"GNSS模块详细定位数据");
        list.put(0x0B,"道路运输卡IC卡信息");
        list.put(0x41,"串口1透传");
        list.put(0x42,"串口2透传");

        int type = cmd.readInt();
        builder.append("透传消息类型("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("透传消息内容:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }
}
